$(function() {
	brandlist();
})
$('.navigation_n div').hover(function(){
	var index = $(this).index();
	if(index == 1){
		$('.navigation_n div ul li').click(function(e){
			e.stopPropagation();
			var index = $(this).index();
			if(index == 0){
				window.location.href = './firststep.html'
			}else if(index == 1){
				window.location.href = './specification.html'
			}else if(index == 2){
				window.location.href = './trademark.html'
			}
		})
	}else if(index == 2){
		$('.navigation_n div ul li').click(function(e){
			e.stopPropagation();
			var index = $(this).index();
			if(index == 0){
				window.location.href = '../indent/goodsindent.html'
			}else if(index == 2){
				window.location.href = '../indent/evaluate.html'
			}
		})
	}
})
//打开模板
$('.addbrand').click(function(){
	$('.new').css('display','block');
})
//放弃操作
$('.abandon').click(function(){
	$('.new').css('display','none');
})



//确认操作
$('.submit').click(function(){
	var goodsname = $('.goodsname').val();
	var logoimg = $('.logoimg').attr('src');
	if(goodsname != '' && logoimg != ''){
		$.ajax({
			type:'post',
			url:URL.interface.addbrand,
			dataType:'json',
			data:{
				brandName:goodsname,
				brandLogo:logoimg
			},
			success:function(e){
				if(e.code == '10000'){
					$('.new').css('display','none');
					window.location.reload();
				}
			}
		})	
	}else{
		alert('完善信息')
	}
	
})

var brand = $('#brand').html();
var brandPages = Handlebars.compile(brand);

//品牌列表
function brandlist() {
	$.ajax({
		type: 'post',
		url: URL.interface.getBrandList,
		dataType: 'json',
		success: function(e) {
			if(e.code == '10000') {
				$("#brandL").html(brandPages(e.data));
				$('.del').click(function(){
					var id = $(this).attr("data_id");
					$.ajax({
						type:'post',
						url:URL.interface.delBrand,
						dataType:'json',
						data:{
							brandId:id
						},
						success:function(e){
//							console.log(e)
							if(e.code == '10000'){
								window.location.reload();
								alert('删除成功')
							}
						}
					})
				})
				
				//打开模板
				$('.compile').click(function(){
					$('.news').css('display','block');
					var id = $(this).attr("data_id");
					var name = $(this).attr("data_name");
					var logo = $(this).attr("data_logo");
					$('.goodsnames').val(name);
					$(".logoimgs").attr("src",logo);
					//修改
					$('.submits').click(function(){
						$.ajax({
							type:"post",
							url:URL.interface.editBrand,
							dataType:'json',
							data:{
								brandId:id,
								brandName:$('.goodsnames').val(),
								brandLogo:$(".logoimgs")[0].src
							},
							success:function(e){
//								console.log(e)
								if(e.code == '10000'){
									$('.news').css('display','none');
									window.location.reload();
								}
							}
						});
					})
				})
				//放弃操作
				$('.abandons').click(function(){
					$('.news').css('display','none');
				})
				
				
				
			}
		}
	})
}

